<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

			<%@ include file="/include/gnb.jsp"%>
			<!-- Main Start -->
			<div id="maincontainer">
				<!-- LeftMenu Start -->
				<div id="leftmenu">
					<%@ include file="/include/lnb.jsp"%>
				</div>
				<!-- Contants Start -->
				<div id="contants">
					<div class="height_10p"></div>
					<form id="commonForm" name="commonForm" method="post">
						<input type="hidden" id="_groupId" name="_groupId" value="${_groupId}" />
						<input type="hidden" id="_menuId" name="_menuId" value="${_menuId}" />
						<input type="hidden" id="_menuNm" name="_menuNm" value="${_menuNm}" />
						<input type="hidden" id="_menuAuth" name="_menuAuth" value="${_menuAuth}" />
						<input type="hidden" id="_prevUpCode" name="_prevUpCode" value="${_prevUpCode}" />
						<input type="hidden" id="_prevCode" name="_prevCode" value="${_prevCode}" />
					</form>
					<div id="ajaxDivList" class="noborder"></div>
				</div>
				<!-- Contants End -->
			</div>
		</div>
		<!-- Footer Start -->
		<div id="footer">
			<%@ include file="/include/footer.jsp"%>
		</div>
	</div>

<script>
var url = "menuImageMgmt.action";
var params = "target=miList";
var targetElement = "ajaxDivList";

var pmModule = {
		loadList: function() {
			var rParams = params + "&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? ($("#isNew").val() == "Y" ? "&searchVal1=" + $("#searchVal1").val() : "&" + $("#searchForm").serialize()) : "");

			this.makeList(url, rParams, targetElement);
		},
		
		setBinding: function() {
		},
		
		setUnbinding: function() {
		},
		
		setFileAdd: function(that) {
			var fileCount = $("input[type=file]").length;
			var strHtml = "<tr>"
							+ "<th>첨부 파일 #" + (fileCount + 1) + "</th>"
							+ "<td>"
							+ "<input type=\"file\" id=\"imageFile" + (fileCount + 1) + "\" name=\"imageFile" + (fileCount + 1) + "\" class=\"input_text\" />"
							+ "</td>"
							+ "</tr>";
							
			$(that).parent().parent().parent().append(strHtml);
		},
		
		selectGroup: function(groupId) {
			$("#groupForm .selected").removeClass("selected");
			$("#groupForm #group_" + groupId).addClass("selected");
			
			$("#_prevCode").val(groupId);
			
			var rParams = "target=miDetail&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? ($("#isNew").val() == "Y" ? "&searchVal1=" + $("#searchVal1").val() : "&" + $("#searchForm").serialize()) : "");

			this.makeList(url, rParams, "ajaxDivImageList");
		},
		
		getViewImage: function(fileName, fileWidth, fileHeight) {
			var screenWidth = document.body.clientWidth - 100;
			var screenHeight = document.body.clientHeight - 200;
			var imgWidth = parseInt(fileWidth);
			var imgHeight = parseInt(fileHeight) - 11;
			
			if (screenWidth < imgWidth) {
				imgWidth = screenWidth;
			}

			if (screenHeight < imgHeight) {
				imgHeight = screenHeight;
			}
			
			frame_popup(url + "?target=miViewImage&imageFileNew=" + fileName + "&imageFileWidth=" + imgWidth + "&imageFileHeight=" + (parseInt(imgHeight) + 20), "원본 이미지 보기", imgWidth, imgHeight);
		},

		setDelete: function() {
			if (!confirm("해당 항목을 삭제합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=miDelete&" + $("#commonForm").serialize() + "&" + $("#imageForm").serialize();

			this.makeList(url, rParams, "ajaxDivImageList");
		},

		setModify: function() {
			$("#imageForm").find("input[type=text]").removeAttr("disabled");
			$("#imageForm").find("input[type=password]").removeAttr("disabled");
			$("#imageForm").find("input[type=radio]").removeAttr("disabled");
			$("#imageForm").find("input[type=file]").show();
			$("#imageForm").find("select").removeAttr("disabled");
			$("#imageForm").find("textarea").removeAttr("disabled");
			$(".fileDiv").hide();
			$(".btnModify").hide();
			$(".btnSave").show();
			$("#imageForm").append("<input type=\"hidden\" id=\"_groupId\" name=\"_groupId\" value=\"" + $("#_groupId").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_menuId\" name=\"_menuId\" value=\"" + $("#_menuId").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_menuType\" name=\"_menuType\" value=\"" + $("#_menuType").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_menuNm\" name=\"_menuNm\" value=\"" + $("#_menuNm").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_menuAuth\" name=\"_menuAuth\" value=\"" + $("#_menuAuth").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_prevUpCode\" name=\"_prevUpCode\" value=\"" + $("#_prevUpCode").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_prevCode\" name=\"_prevCode\" value=\"" + $("#_prevCode").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_startRowNo\" name=\"_startRowNo\" value=\"" + $("#_startRowNo").val() + "\" />");
			$("#imageForm").append("<input type=\"hidden\" id=\"_pageSize\" name=\"_pageSize\" value=\"" + $("#_pageSize").val() + "\" />");
		},

		save: function() {
			var isFileCheck = "";
			var fileCount = $("input[type=file]").length;
			for (var i = 1; i <= fileCount; i++) {
				if ($("#imageFile" + i).val() != "") {
					isFileCheck = isFileCheck + (i == 1 ? "" : "|") + "1";
				} else {
					isFileCheck = isFileCheck + (i == 1 ? "" : "|") + "0";
				}
			}
			$("#isFileCheck").val(isFileCheck);
			
			if (!confirm("해당 항목을 저장합니다. 계속 하시겠습니까?")) {
				return;
			}

			$("#imageForm").attr("action","menuImageAdd.action");
			$("#imageForm").attr("target","formProcess");
			$("#imageForm").submit();
			
			this.complete();
		},
		
		complete: function() {
			$("#imageForm").find("input[type=text]").attr("disabled","disabled");
			$("#imageForm").find("input[type=password]").attr("disabled","disabled");
			$("#imageForm").find("input[type=radio]").attr("disabled","disabled");
			$("#imageForm").find("input[type=file]").hide();
			$("#imageForm").find("select").attr("disabled","disabled");
			$("#imageForm").find("textarea").attr("disabled","disabled");
			$(".fileDiv").show();
			$(".btnModify").show();
			$(".btnSave").hide();
			$("#imageForm > #_groupId").remove();
			$("#imageForm > #_menuId").remove();
			$("#imageForm > #_menuType").remove();
			$("#imageForm > #_menuNm").remove();
			$("#imageForm > #_menuAuth").remove();
			$("#imageForm > #_prevUpCode").remove();
			$("#imageForm > #_prevCode").remove();
			$("#imageForm > #_startRowNo").remove();
			$("#imageForm > #_pageSize").remove();
		},

		reset: function(cmd) {
			$("#imageForm").each(function(){
				this.reset();
			});

			if (cmd == "reset") {
				this.complete();
			}
		},

		getList: function(cmd) {
			if (cmd == "reset") {
				this.reset(cmd);
			}
			this.loadList();
		},
		
		makeList: function(sUrl, sParams, sTarget) {
			var that = this;
			
			$.ajax({
				url : sUrl,
				type : "POST",
				data : sParams,
				dataType : "html",
				success : function(data){
					$("#" + sTarget).html(data);

					that.setUnbinding();
					that.setBinding();
					that.initPage();

					if ($("#nodata").html() != null) {
					}
				}
			});
		},
		
		initPage: function(){
			this.initPageSize();
		},
		     
		initPageSize: function(){
		    var msg = "";
			
			// warp
			var valueGwpw = getObjectValue("#warp", "width"); 
			var gwpw = (valueGwpw == null) ? 0 : valueGwpw; // 대상 전체 폭
			var valueGwph = getObjectValue("#warp", "height"); 
			var gwph = (valueGwph == null) ? 0 : valueGwph; // 대상 전체 높이
			msg = appendMessage(msg, "#warp");
			
			setObjectValue("#container", "width", Math.round(gwpw - 40));
			
			// container
			var valueGcw = getObjectValue("#container", "width"); 
			var gcw = (valueGcw == null) ? 0 : valueGcw; // 대상 전체 폭
			var valueGch = getObjectValue("#container", "height"); 
			var gch = (valueGch == null) ? 0 : valueGch; // 대상 전체 높이
			msg = appendMessage(msg, "#container");
			
			// contants
			setObjectValue("#contants", "width", Math.round(gcw - 180 - 10));
			msg = appendMessage(msg, "#contants");
			
			// formtitle
			var valueGftw = getObjectValue("#formtitle", "width");
			var gftw = (valueGftw == null) ? 0 : valueGftw; // 대상 전체 폭
			var valueGfth = getObjectValue("#formtitle", "height"); 
			var gfth = (valueGfth == null) ? 0 : valueGfth; // 대상 전체 높이
			
			// formlist
			var valueGccw = getObjectValue("#contants", "width"); 
			var gccw = (valueGccw == null) ? 0 : valueGccw; // 대상 전체 폭
			var valueGcch = getObjectValue("#contants", "height"); 
			var gcch = (valueGcch == null) ? 0 : valueGcch; // 대상 전체 높이
			
			setObjectValue("#formlist3l", "height", Math.round(gcch - gfth - 35));
			setObjectValue("#formlist3r", "height", Math.round(gcch - gfth - 35));
			setObjectValue("#ajaxDivImageList", "height", Math.round(gcch - gfth - 68));
			
			var formw = getObjectValue("#formlist3l", "width"); 
			setObjectValue("#formlist3r", "width", Math.round(gccw - formw - 30));
			msg = appendMessage(msg, "#formlist3r");
			
			$(".LoggingMessage").html(msg);
		}
};

$(document).ready(function(){
	pmModule.loadList();
	pmModule.initPage();
});

$(window).resize(function(){
	pmModule.initPage();
});
</script>
</body>
</html>
